﻿#include <vector>
#include <iostream>

struct Fragment {
    int length;
    int offset;
};

std::vector<Fragment> fragmentPacket(int packetLength, const std::vector<int>& pathMTUs) {
    std::vector<Fragment> fragments;
    int headerLength = 20; // 固定报文头长度
    int dataLength = packetLength - headerLength; // 数据部分长度
    int offset = 0;

    for (int mtu : pathMTUs) {
        int maxDataLength = mtu - headerLength; // 每个分片最大数据长度
        while (dataLength > 0) {
            int fragmentLength = std::min(dataLength, maxDataLength);
            fragments.push_back({ fragmentLength + headerLength, offset });
            offset += fragmentLength;
            dataLength -= fragmentLength;
        }
    }

    return fragments;
}

int main() {
    int packetLength = 24000; // 示例报文长度
    std::vector<int> pathMTUs = { 4325, 2346, 1500, 4464, 2346 }; // 示例路径MTU
    std::vector<Fragment> fragments = fragmentPacket(packetLength, pathMTUs);

    for (const auto& fragment : fragments) {
        std::cout << "Fragment Length: " << fragment.length << ", Offset: " << fragment.offset << std::endl;
    }

    return 0;
}